<?php

// @formatter:off
/**
 * @file ratesof.php
 * @author Alejandro Dario Simi
 * @date $Date: 2014-05-04 01:33:52 +0000 (Sun, 04 May 2014) $
 *
 * $Id: ratesof.php 111 2014-05-04 01:33:52Z daemonraco@gmail.com $
 * $URL: http://wcomix.googlecode.com/svn/trunk/frontview/actions/info/ratesof.php $
 */
// @formatter:on

class ActionControllerInfoRatesof extends WCActionController {
//	//
//	// Magic methods.
//	public function __construct() {
//		parent::__construct();
//
//		if(isset($_REQUEST["removable"])) {
//			$this->_selector["extra"] = "R";
//		}
//		if(isset($_REQUEST["editable"])) {
//			$this->_selector["extra"] = "E";
//		}
//	}
	//
	// Public methods.
	public function check() {
		$check = parent::check();

		if($check == WC_HTTPERROR_OK) {
			global $wcProfile;
			global $wcComic;
			global $wcImage;

			if(!$wcProfile->allowedAny(WC_PERM_COMIC_VIEW, WC_PERM_IMAGE_VIEW)) {
				$check = WC_HTTPERROR_FORBIDDEN;

				global $errno;
				global $error;

				$errno = $check;
				$error = "You're not allowed to list tags";
			}
			if($check == WC_HTTPERROR_OK && (!$wcComic || !$wcComic->ok())) {
				if(!$wcImage || !$wcImage->ok()) {
					$check = WC_HTTPERROR_BAD_REQUEST;

					global $errno;
					global $error;

					$errno = $check;
					$error = "You haven't specified neight a comic nor an image";
				}
			}
		}

		return $check;
	}
	//
	// Protected methods.
	protected function subRun() {
		$ok = true;
		//
		// Loading global pointers.
		global $wcComic;
		global $wcImage;
		global $wcUser;

		$helper = WCReadRate::I();
		$globalData = false;
		$userData = false;

		if($wcComic && $wcComic->ok()) {
			$globalData = $helper->comicReadRate($wcComic);
			if($wcUser && $wcUser->ok()) {
				$userData = $helper->userComicReadRate($wcComic, $wcUser);
			}
		} elseif($wcImage && $wcImage->ok()) {
			$globalData = $helper->imageReadRate($wcImage);
			if($wcUser && $wcUser->ok()) {
				$userData = $helper->userImageReadRate($wcImage, $wcUser);
			}
		}

		foreach($globalData as $key => $value) {
			$prop = "info_rr_{$key}";
			$this->_manager->{$prop} = $value;
		}
		if($userData && $userData ["rate"]["date"]) {
			foreach($userData as $key => $value) {
				$prop = "info_rr_user_{$key}";
				foreach($value as $skey => $svalue) {
					$sprop = "{$prop}_{$skey}";
					$this->_manager->{$sprop} = $svalue;
				}
			}
		}

		return $ok;
	}
}

?>